package com.chat.controller;

import com.chat.domain.dto.LoginDTO;
import com.chat.domain.dto.UserPasswordDTO;
import com.chat.service.UserService;
import com.chat.util.Result;
import com.chat.domain.dto.UserProfileDTO;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 用户控制器
 *
 * @author wb
 * @since 2024-08-21
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    // 登录
    @PostMapping("/login")
    public Result<Boolean> login(@Valid LoginDTO loginDTO, HttpSession session) {
        return userService.login(loginDTO, session) ? Result.ok() : Result.fail();
    }


    // 修改个人信息
    @PostMapping("/update-profile")
    public Result<Boolean> updateProfile(@Valid UserProfileDTO userProfileDTO, HttpSession session) {
        return userService.updateProfile(userProfileDTO, session) ? Result.ok() : Result.fail();
    }


    // 修改密码
    @PostMapping("/update-password")
    public Result<Boolean> updatePassword(UserPasswordDTO userPasswordDTO, HttpSession session) {
        return userService.updatePassword(userPasswordDTO, session) ? Result.ok() : Result.fail();
    }


    // 文件上传
    @PostMapping("/upload-file")
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) {
        // TODO 文件上传
        System.out.println(file.getOriginalFilename());
        return Result.ok("https://img0.baidu.com/it/u=3265037425,1108192406&fm=253&fmt=auto&app=138&f=JPEG");
    }

}
